<template>
  <div class="modify-dialog">
    <slot>
      <el-button size="small" type="primary" @click="showDialog()">
        新增角色
      </el-button>
    </slot>
    <el-dialog v-bind="dialogOpts" :visible.sync="dialogVisible">
      <Form v-bind="formOpts" v-on="formEvent">
        <template #formBtn>
          <div class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="onConfirm"> 确 定 </el-button>
          </div>
        </template>
      </Form>
    </el-dialog>
  </div>
</template>

<script>
import modifyMixins from "@/mixins/modifyMixins.vue";
export default {
  mixins: [modifyMixins],
  data() {
    return {
      form: {
        permission: {
          tag: "el-input",
          label: "角色权限",
          value: "",
          props: {
            clearable: true,
            placeholder: "请输入角色权限",
          },
        },
        name: {
          tag: "el-input",
          label: "角色名",
          value: "",
          props: {
            clearable: true,
            placeholder: "请输入角色名",
          },
        },
        description: {
          tag: "el-input",
          label: "角色描述",
          value: "",
          props: {
            clearable: true,
            placeholder: "请输入角色描述",
          },
        },
      },
    };
  },
  methods: {
    onSubmit(form) {
      const { modify, row } = this;
      if (modify === "add") this.$api.addRole(form).then(this.submitDoneMsg);
      else if (modify === "edit")
        this.$api.patchRole({ ...form, id: row.id }).then(this.submitDoneMsg);
    },
  },
};
</script>

<style lang="less" scoped></style>
